<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'set';
$return=array();
if($_RQ['op']=='set'){
	$return['item']=array();
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'虚拟秒杀',
		'tabs'=>array(
			array('op'=>'add','title'=>'生成虚拟订单_Order info'),
		),
		'edit'=>array(
			array('title'=>'所有虚拟订单，必须是虚拟会员才行，或手动添加会员','type'=>'tip'),
			array('name'=>'is_new','title'=>'新会员？','type'=>'switch'),
			array('type'=>'choose','title'=>'选择虚拟会员','name'=>'mid','action'=>'core/member.get_member//is_virtual=1','choose_title'=>'选择虚拟会员','show'=>array('is_new <>'=>1),'help'=>'虚拟会员添加方法：我的会员--会员列表--导入虚拟用户'),
			array('type'=>'choose','title'=>'选择当前秒杀商品','name'=>'goodsid','action'=>'/setorder/get_goods/','choose_title'=>'选择商品'),
			array('name'=>'name','title'=>'会员昵称','type'=>'string','show'=>array('is_new'=>1)),
			array('name'=>'avatar','title'=>'会员头像','type'=>'image','show'=>array('is_new'=>1)),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
		$post=get_postdata();
		if(!$post['goodsid'] || (!$post['mid'] && $post['is_new']!=1)){
			exi('必须选择商品，会员等','error');
		}
		$mid=$post['mid'];
		if($post['is_new']==1){
			$member=array(
				'nickname'=>trim($post['name']),
				'avatar'=>trim($post['avatar']),
				'uniacid'=>$_SESSION['uniacid'],
				'username'=>'user_'.random(10),
				'from_os'=>get_os(),
				'is_virtual'=>1,
				'createtime'=>TIMESTAMP,
			);
			pdo_insert('core_members',$member);
			$mid=pdo_insertid();
		}
		$goods=pdo_get('jy_weishop_goods',array('id'=>$post['goodsid']));
		$goods['total']=1;
		$goods['goodsid']=$goods['id'];
		$new_order=array(
			'mid'=>$mid,
			'price'=>$goods['price'],
			'goodsprice'=>$goods['price'],
			'goods'=>array($goods),
			'addressid'=>$addressid,
			'sendtype'=>1,
			'type'=>1,
			'createtime'=>$createtime,
		);
		$order_id=model('jy_weishop/order')->create($new_order);
		$order=pdo_get('jy_weishop_order',array('id'=>$order_id),array('ordersn','mid','price'));
		$update=array('status'=>1);
		pdo_update('jy_weishop_order',$update,array('id'=>$order_id));
		$this->model('model')->setOrderPay($order_id);
		exi('生成订单成功！');
}
if($_RQ['op']=='get_goods'){
	$getdata=$this->model('model')->get_goods('','','',true);
	if($getdata['goods']){
		foreach($getdata['goods'] as &$item){
			$item['merchtitle']=$item['merchid']>0?'其他商户':'自营平台';
			if($_RQ['op']=='many'){
				$item['res']=array(
					'title'=>$item['title'],
					'id'=>$item['goodsid'],
					'image'=>$item['image'],
				);
			}else{
				$item['res']=$item['goodsid'];
			}
			
		}
	}
	$return['list']=$getdata['goods'];
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['htmls']=array(
			'type'=>'list',
			'tabs'=>array(
				array('op'=>'list','title'=>'商品列表'),
			),
			'list'=>array('data'=>'list','del_one'=>false,'delall'=>false,'edit'=>false,'list'=>array(
				array('name'=>'goodsid','title'=>'商品id','type'=>'string'),
				array('name'=>'title','title'=>'商品名称','type'=>'string'),
				array('name'=>'image','title'=>'商品图片','type'=>'image'),
				array('name'=>'merchtitle','title'=>'所属商户','type'=>'string'),
			),'action'=>array(
				array('type'=>'modal_result','name'=>'res','title_field'=>'title','title'=>'选取'),
			)),
	);
	exi($return);
}
?>